package com.yulan.slide_windows;

import org.junit.Test;

import java.util.HashMap;
import java.util.HashSet;

/**
 * 不重复的最长字串
 * "abcabcbb" == > 3
 */
public class NotDuplicateChildStr {

    public int lengthOfLongestSubstring(String s) {
        HashMap<Character,Integer> map = new HashMap<>();
        int maxLen = 0;
        int start = 0;
        for(int i=0; i<s.length();i++ ){
            start = Math.max(start, map.getOrDefault(s.charAt(i),-1) + 1);
            maxLen = Math.max(maxLen, i - start + 1);
            map.put(s.charAt(i),i);
        }
        return maxLen;
    }

    @Test
    public void test(){
        String str = "abcabcbb";
        System.out.println(lengthOfLongestSubstring(str));
    }
}
